package scripts;
import bot.ScriptMethods;
import javax.swing.JOptionPane;

public class PotionMaker extends ScriptMethods implements Runnable {

	private int primary;
	private int secondary;
	private int unfinished;
	private int potId;

	public void start() {
		getAccountSettings();
		System.gc();

		Object[] options = {"Attack Potion", "Strength Potion", "Stat Restore", "Defense Potion", "Restore Prayer",
							"Super Attack", "Fishing Potion", "Super Strength", "Weapon Poison", "Super Defense",
							"Ranging Potion", "Zamorak"};

		String res1 = (String)JOptionPane.showInputDialog(null, "", "Identify Herbs", JOptionPane.PLAIN_MESSAGE, null, options, options[0]);

		if (res1.equals("Attack Potion")) {
			potId = 474;
			secondary = 270;
			primary = 444;
			unfinished = 454;
		}
		if (res1.equals("Strength Potion")) {
			potId = 222;
			secondary = 220;
			primary = 446;
			unfinished = 456;
		}
		if (res1.equals("Stat Restore")) {
			potId = 477;
			secondary = 219;
			primary = 447;
			unfinished = 457;
		}
		if (res1.equals("Defense Potion")) {
			potId = 480;
			secondary = 471;
			primary = 448;
			unfinished = 458;
		}
		if (res1.equals("Restore Prayer")) {
			potId = 483;
			secondary = 469;
			primary = 448;
			unfinished = 458;
		}
		if (res1.equals("Super Attack")) {
			potId = 486;
			secondary = 270;
			primary = 449;
			unfinished = 459;
		}
		if (res1.equals("Fishing Potion")) {
			potId = 489;
			secondary = 469;
			primary = 450;
			unfinished = 460;
		}
		if (res1.equals("Super Strength")) {
			potId = 492;
			secondary = 220;
			primary = 451;
			unfinished = 461;
		}
		if (res1.equals("Weapon Poison")) {
			potId = 572;
			secondary = 467;
			primary = 451;
			unfinished = 461;
		}
		if (res1.equals("Super Defense")) {
			potId = 495;
			secondary = 471;
			primary = 452;
			unfinished = 462;
		}
		if (res1.equals("Ranging Potion")) {
			potId = 498;
			secondary = 501;
			primary = 453;
			unfinished = 463;
		}
		if (res1.equals("Zamorak")) {
			potId = 501;
			secondary = 936;
			primary = 934;
			unfinished = 935;
		}

		scriptRunning = true;
		scriptThread = new Thread(this);
		scriptThread.start();
	}

	public void stop() {
		System.gc();
		scriptThread = null;
		scriptRunning = false;
		debug("Stopped script.");
	}

	public void run() {
		while (scriptRunning) {
			try {
				handleEvents();

				// Drop jugs when making Wine of Zamorak potions
				if (invContains(140)) {
					dropItem(140);
					wait(600);
				}

				// Make unfinished potions
				if (!isSleeping() && invContains(primary) && invContains(secondary)) {
					useItemOnItem(primary, 464);
					wait(600);
				}

				// When finished making unfinished potions, add
				// the secondary ingredients.
				if (!isSleeping() && invContains(unfinished) && invContains(secondary) && !invContains(primary)) {
					useItemOnItem(unfinished, secondary);
					wait(600);
				}

				if (!invContains(unfinished) && !invContains(secondary) && invContains(potId)) {
					if (bankOpen()) {
							depositAll(potId);
							wait(random(600, 700));
							withdraw(primary, 9);
							wait(random(600, 700));
							withdraw(secondary, 9);
							wait(random(600, 700));
							withdraw(464, 9);
							wait(random(600, 700));
							closeBank();
							wait(600);
					} else {
						openBank();
						wait(2000);
					}
				}
			
				wait(random(50, 80));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public void handleEvents() throws Exception {
		if (welcomeBoxOpen())
			setWelcomeBox();
		if (!isLoggedIn())
			doLogin();
		if (getFatigue() > 80 && !isSleeping()) {
			wait(600);
			useItem(1263);
			wait(600);
		}
		if (getFatigueSleeping() < 10 && isSleeping())
			doSleeping();
	}
}